package com.csailing4cloud.csailing.user.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.csailing4cloud.csailing.common.core.util.CsResponse;
import com.csailing4cloud.csailing.user.api.dto.UserInfo;
import com.csailing4cloud.csailing.user.api.entity.CsUser;
import com.csailing4cloud.csailing.user.biz.service.UserService;
import com.csailing4cloud.csailing.user.service.CsUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author dyh
 * @since 2019-09-21
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private CsUserService csUserService;

    @Autowired
    private UserService userService;

    @GetMapping(value = "/info/{userName}")
    public CsResponse<UserInfo> userInfo(@PathVariable("userName") String userName){
        CsUser csUser = csUserService.getOne(new QueryWrapper<CsUser>().eq("user_name", userName));
        UserInfo userInfo = new UserInfo();
        userInfo.setCsUser(csUser);
        return CsResponse.success(userInfo);
    }

    @GetMapping("/info/test")
    public String testController(){
        return "success";
    }

    @PostMapping("/info/save")
    public CsResponse save(@RequestBody CsUser csUser){
        userService.saveTest(csUser);
        return CsResponse.success(null);
    }

}

